/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package javagameengine;

import java.awt.MouseInfo;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

/**
 *
 * @author jimi
 */
public class Mouse implements MouseListener
{

	private Mouse()
	{
	}
	public static Mouse is = new Mouse();
	boolean btns[] = new boolean[3];

	public enum BTN
	{

		left( 0 ),
		right( 1 ),
		middle( 2 );
		private final int index;

		private BTN( int index )
		{
			this.index = index;
		}

		int index()
		{
			return this.index;
		}
	}

	public Point at()
	{
		Point p = new Point();
		p.x = MouseInfo.getPointerInfo().getLocation().x - RenderScreen.current.frame.getX();
		p.y = MouseInfo.getPointerInfo().getLocation().y - RenderScreen.current.frame.getY();
		return p;
	}

	@Override
	public void mouseClicked( MouseEvent e )
	{
		switch( e.getButton() )
		{
			case MouseEvent.BUTTON1:
				break;
			case MouseEvent.BUTTON2:
				break;
			case MouseEvent.BUTTON3:
				break;
		}
	}

	public boolean pressed( BTN b )
	{
		return btns[b.index()];
	}

	public boolean released( BTN b )
	{
		return !btns[b.index()];
	}

	@Override
	public void mousePressed( MouseEvent e )
	{
		switch( e.getButton() )
		{
			case MouseEvent.BUTTON1:
				btns[BTN.left.index()] = true;
				break;
			case MouseEvent.BUTTON3:
				btns[BTN.right.index()] = true;
				break;
			case MouseEvent.BUTTON2:
				btns[BTN.middle.index()] = true;
				break;
		}
	}

	@Override
	public void mouseReleased( MouseEvent e )
	{
		switch( e.getButton() )
		{
			case MouseEvent.BUTTON1:
				btns[BTN.left.index()] = false;
				break;
			case MouseEvent.BUTTON3:
				btns[BTN.right.index()] = false;
				break;
			case MouseEvent.BUTTON2:
				btns[BTN.middle.index()] = false;
				break;
		}
	}

	@Override
	public void mouseEntered( MouseEvent e )
	{
	}

	@Override
	public void mouseExited( MouseEvent e )
	{
	}
}
